<?php
//connect to mysql database
require("config.php");
//start session
session_start();

//Check to see if the url variable is set and it exists in the database
if(isset($_GET['id'])) {
	$id = preg_replace('#[^0-9]#i','',$_GET['id']);
	//use this variable to check if the ID exists, if yes then get the product details
	//if no, exit and give a message
	$sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
	$productCount = mysql_num_rows($sql); // count the output amount
	if ($productCount > 0) {
		//get all the product details
		while($row = mysql_fetch_array($sql)){
				 $product_name = $row["product_name"];
				 $price = $row["price"];
				 $details = $row["details"];
				 $category = $row["category"];
				 $subcategory = $row["subcategory"];
				 $original_quantity = $row["original_quantity"];
				 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
			//product_name, price, details, category, subcategory, date_added
	    }
	} else {
		echo "That item does not exist";
		exit();
	}
} else {
	echo "No product in the system with that ID";
	exit();	
}
mysql_close();
?>